import { ApiProperty } from '@nestjs/swagger';
import {
  IsEnum,
  IsNotEmpty,
  IsOptional,
  IsString,
  IsUUID,
  MaxLength,
  IsArray,
} from 'class-validator';
import { ContentType } from '../../common/enums';

export class CreateContentDto {
  @ApiProperty({
    description: '内容标题',
    maxLength: 128,
    example: '如何提高工作效率',
  })
  @IsString()
  @IsNotEmpty()
  @MaxLength(128)
  title: string;

  @ApiProperty({
    description: '内容类型，支持纯文本(text)和Markdown',
    enum: ContentType,
    example: ContentType.MARKDOWN,
  })
  @IsEnum(ContentType)
  @IsNotEmpty()
  contentType: ContentType;

  @ApiProperty({
    description: '内容主体，存储原始文本或 Markdown 源码',
    example: '# 工作效率提升指南\n\n## 1. 合理规划时间\n\n时间管理是提高效率的关键...',
  })
  @IsString()
  @IsNotEmpty()
  body: string;

  @ApiProperty({
    description: '推荐理由，可为空',
    example: '这篇文章提供了实用的工作效率提升方法',
    required: false,
    nullable: true,
  })
  @IsString()
  @IsOptional()
  recommendReason?: string;

  @ApiProperty({
    description: '作为模板的内容 ID，非模板内容可为空',
    format: 'uuid',
    required: false,
    nullable: true,
  })
  @IsUUID()
  @IsOptional()
  templateId?: string;

  @ApiProperty({
    description: '关联的标签ID列表',
    type: [String],
    format: 'uuid',
    required: false,
    example: ['550e8400-e29b-41d4-a716-446655440000', '550e8400-e29b-41d4-a716-446655440001'],
  })
  @IsArray()
  @IsUUID(undefined, { each: true })
  @IsOptional()
  tagIds?: string[];

  @ApiProperty({
    description: '关联的附件ID列表',
    type: [String],
    format: 'uuid',
    required: false,
    example: ['550e8400-e29b-41d4-a716-446655440000', '550e8400-e29b-41d4-a716-446655440001'],
  })
  @IsArray()
  @IsUUID(undefined, { each: true })
  @IsOptional()
  attachmentIds?: string[];
}
